﻿using EmbeddedSharp.Core;
using System.Text;

namespace Ascend.Runtime.Core {
    public class AscendLexer : Lexer {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        public AscendLexer(string source)
            : base(source) {
        }

        /// <summary>
        /// Skips a section of comment begins with (* and ends with *).
        /// </summary>
        protected override void SkipComments() {
            char chr = source[Index];
            StringBuilder buffer = new StringBuilder();

            if (chr == '(') {
                char cxx = source[Index + 1];
                if (cxx == '*') {
                    Index++;
                    buffer.Append(chr).Append(cxx);
                    while (Index + 1 < source.Length) {
                        cxx = source[++Index];
                        buffer.Append(cxx);
                        if (cxx == '*' && source[Index + 1] == ')') {
                            cxx = source[++Index];
                            buffer.Append(cxx);
                            break;
                        }                        
                    }
                }

                LastComment = buffer.ToString();
            }
        }
    }
}
